
#include "../basic/operator.h"

/* make continuation. */
//创建延续
Cell* make_continuation(Scheme *sc, Cell* d) {
	Cell* p = make_cell(sc, G_NIL, d);
	// (p)->_flag = T_CONTINUATION;
	(p)->_type = CONTINUATION_TYPE;
	return p;
}

/* call-with-current-continuation */
//将当前堆栈作为参数传给 作为过程的call/cc的参数
Cell* op_continuation(Scheme *sc) {
	sc->code = car(sc->args);
	sc->args = cons(sc, make_continuation(sc, sc->callStack), G_NIL);
	sc->op = cell_op_apply;
	return G_TRUE;
}

void init_continuation_operators(Scheme *sc) {
	ADD_OPERATOR(sc, "call-with-current-continuation", continuation);
}

